package com.googlecode.FWT.view.buttons.back
{
	import com.googlecode.FWT.core.NotificationNames;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Button;
	
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class ButtonMediator extends Mediator
	{
		public function ButtonMediator(mediatorName:String, viewComponent:Button)
		{
			super(mediatorName, viewComponent);
		}
		
		/**
		 * PureMVC callback - the mediator has been registered with the framework.
		 * Carries out framework-dependent initialisation code. 
		 */
		override public function onRegister():void
		{
			// add event listeners now that the Mediator is part of the framework
			viewRef.addEventListener(MouseEvent.CLICK, onButtonClick);
		}
		
		/**
		 * PureMVC callback - the mediator has been removed from the framework.
		 * Carries out framework-related cleanup code. 
		 */		
		override public function onRemove():void
		{
			// remove event listeners now - the events don't need to be handled if the mediator isn't part of the framework anymore 
			viewRef.removeEventListener(MouseEvent.CLICK, onButtonClick);
		}
		/**
		 * Handle the case of when a page is changed. 
		 * @return 
		 * 
		 */
		protected function onButtonClick(evt:MouseEvent):void
		{
			sendNotification(NotificationNames.BUTTON_CLICK, evt);
		}
		/**
		 * Return a typed reference to the viewComponent.  
		 * @return
		 */		
		protected function get viewRef():Button
		{
			return viewComponent as Button;
		}
	}
}